<?php

namespace app\after\controller;

use think\cache\driver\Redis;
use think\Controller;
use think\Request;

class Show extends Controller
{
//    展示用户列表
    public function show()
    {
//        建立查询
        $word = input('word');
        $data = \app\after\model\Show::show($word);
        $this->assign('data', $data);
        //生成redis
        $redis = new Redis();
        if ($redis->has('redisData')) {
            echo 'redis';
            $redis->get('data');
        } else {
            $data = \app\after\model\Show::show($word);
            echo 'mysql';
            $redis->set('redisData', $data);
        }
        return view();
    }

    //清除redis
    public function unclear()
    {
        $redis = new Redis();
        $res = $redis->get('redisData');
        $m1 = memory_get_usage();
        unset($res);
        $m2 = memory_get_usage();
        $redis->clear();
        $m = $m1 - $m2;
        return json(['code' => 200, 'msg' => '清除成功返回结果为', $m]);
    }
}
